﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETPerformance.App_BusinessLogic.BasePages;
using ASPNETPerformance.App_BusinessLogic.Helpers;
using ASPNETPerformance.App_BusinessLogic.Utils;

namespace ASPNETPerformance.UserControls {
    public partial class Part1 : BaseUserControl {
        protected void Page_Load( object sender, EventArgs e ) {
            if ( !this.Page.IsPostBack ) {
                BindPart1();
            }
        }

        private void BindPart1() {
            this.cbEnableViewState.Checked = CommonHelper.GetCookieBool( "IsEnableViewState" );
            this.cbEnableCompression.Checked = CommonHelper.GetCookieBool( "IsViewStateCompression" );
            this.cbEnableOnTheServer.Checked = CommonHelper.GetCookieBool( "IsOnTheServer" );
        }

        protected void BtnPart1_Click( object sender, EventArgs e ) {
            SaveInfo();

            this.lblPart1Result.Text = "保存成功。";
        }

        public void SaveInfo() {
            CommonHelper.SetCookie( "IsEnableViewState",
          this.cbEnableViewState.Checked.ToString().Trim(), new TimeSpan( 365, 0, 0, 0, 0 ) );

            CommonHelper.SetCookie( "IsViewStateCompression",
                this.cbEnableCompression.Checked.ToString().Trim(), new TimeSpan( 365, 0, 0, 0, 0 ) );

            CommonHelper.SetCookie( "IsOnTheServer",
                this.cbEnableOnTheServer.Checked.ToString().Trim(), new TimeSpan( 365, 0, 0, 0, 0 ) );
        }
    }
}